package com.example.su_shi_tan_bas_lib.album.utils;

import android.graphics.Canvas;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class GalleryDecoration extends RecyclerView.ItemDecoration {


    private int currentPos = RecyclerView.NO_POSITION;

    public int getCurrentPos() {
        return currentPos;
    }

    private GalleryIndexIndicator indexIndicator;
    public void setIndexIndicator(GalleryIndexIndicator indexIndicator) {
        this.indexIndicator = indexIndicator;
    }

    @Override
    public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
        super.onDrawOver(c, parent, state);
        RecyclerView.Adapter adapter = parent.getAdapter();
        if (adapter == null) return;

        int itemCount = adapter.getItemCount();

        LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager();
        if (layoutManager == null) return;

        int activePosition = layoutManager.findFirstCompletelyVisibleItemPosition();
        if (activePosition != RecyclerView.NO_POSITION && indexIndicator != null) {
            currentPos = activePosition;
            indexIndicator.getIndexIndicator(currentPos, itemCount);
        }
    }

    public interface GalleryIndexIndicator {
        void getIndexIndicator(int index, int itemCount);
    }

}